﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>绑定学员</title>
		<link href="css/identity_member_auth_input1.css" rel="stylesheet" />
		<script src="../../backstage/lib/jquery/1.9.1/jquery.js"></script>
		<script src="../../layui/src/layui.js"></script>
        <script src="css/identity_member_auth_input_js1.js"></script>
		<link href="../../layui/layui/css/layui.css" rel="stylesheet" /></head>
	<body onload="getAllStudentListManager()">
		<form class="layui-form layui-form-pane1" action="" lay-filter="first" id="student-add">
			<div class="contaniner fixed-cont">

            <div class="contaniner fixed-cont">
				<div class="tkyy">绑定学生
					<span>*</span></div>
				<div class="layui-form-item">
					<select id="student-selected" lay-filter="selected" class="select" lay-verify="type" name="selected"></select>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="tkyy">绑定验证码（对应学生会在公众号中自动获得）
					<span>*</span></div>
				<input type="text" name="inputCode" id="inputCode" lay-verify="required|title" required="" placeholder="请输入学生姓名" autocomplete="off" class="layui-input" /></div>
			<div class="tkyy">绑定说明
				<span>*</span></div>
			<div class="bangding">为了学员的隐私与安全，需要获得学员的验证号码</div>
			<div class="bangding">才能继续绑定</div>
			<!--2-->
		        <a href="#"><div class="submit_button" onclick="bindingManager()">提交申请</div></a>
                </div>
		</form>
		<script type="text/javascript">
		    function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg); //search,查询？后面的参数，并匹配正则
    if (r != null) return unescape(r[2]);
    return null;
}

		    // 获取所有学生
		    function getAllStudentListManager() { 
		        var args = $.param({
		            status: "1"
		        })
		        $.ajax({
		            url:'../../ChireInter/Students/Students_List.ashx',
		            data: args,
		            type: 'post',
		            dataType: 'json',
		            success: function (res) {
		                if (res.errCode == 200) {
		                    var html = "";

		                    html += "<option value=" + "\"" + "null" + "\"" + ">" + "请选择" + "</option>";

		                    for (var i in res.data.list) {
		                        html += "<option value=" + "\"" + res.data.list[i].id + "\"" + ">" + res.data.list[i].name + "</option>";
		                    }

		                    var oContent = $('#student-selected');
		                    oContent.prepend(html);
		                    reloadFrom();
		                } else {

		                }
		            },
		            error: function (err) {

		            }
		        })
		    }
		 
		    function addNoticeManager(authKey) {
		        if (authKey == "请选择" || authKey == "null") {
		            return;
		        }

		        var authType = GetQueryString("auth_type");
		        var code = GetQueryString("code");

		        var args = $.param({
		            auth_type: authType,
		            code: code,
		            auth_key: authKey,
		        })
		        $.ajax({
		            url: '../../ChireInter/Identity/Identity_Auth_Notice.ashx',
		            data: args,
		            type: 'post',
		            dataType: 'json',
		            success: function (res) {
		                if (res.errCode == 200) {
		                    alert("已将验证码下发至学员微信。请联系学员获取");
		                } else {
		                    alert(res.errMsg);
		                }
		            },
		            error: function (err) {

		            }
		        })

		    }


		    // 进行绑定
		    function bindingManager() {
		        // 获取微信的code
		        var code = GetQueryString('code');
		        // 获取绑定
		        var identity = GetQueryString('auth_type');
		        // 获取输入的邀请码
		        var authCode = document.getElementById("inputCode").value;
		        // 获取绑定的学生
		        var studentId = $('#student-selected').val();

		        var args = $.param({
		            "code": code,
		            "auth_type": identity,
		            "authCode": authCode,
		            "studentId": studentId,
		        });
		      
		        $.ajax({
		            url: '../../ChireInter/Identity/Identity_Auth.ashx',
		            data: args,
		            type: 'post',
		            dataType: 'json',
		            success: function (res) {
		                if (res.errCode == 200) {
		                    var infohref = "../StudentInfo/student_info_card.html?id=" + res.data.student.id + "&auth_type=0";
		                    window.location.href = infohref;
		                    alert(res.errMsg);
		                } else {
		                    alert(res.errMsg);
		                }
		            },
		            error: function (err) {

		            }
		        })
		    }

		    // 刷新表单
		    function reloadFrom() {
		        layui.use(['form'],
				function() {
				    var form = layui.form,
					layer = layui.layer;
				    form.on('select(selected)',
					function (data) {
					    addNoticeManager(data.value);
				
					});
				});
		    }</script>
	</body>

</html>